package myzzyl.controller;



import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import myzzyl.domain.dto.NursingLevelDto;
import myzzyl.domain.vo.NursingLevelVo;
import myzzyl.response.BaseResponse;
import myzzyl.response.PageResponse;
import myzzyl.service.NursingLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Tag(name = "护理等级相关")
@Slf4j
public class NursingLevelController {

    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     * 分页获取所有护理等级
     */
    @GetMapping("/listByPage")
    public BaseResponse<PageResponse<NursingLevelVo>> getAll(
            @RequestParam(name = "name", required = false) String name,
            @RequestParam(name = "status", required = false) Integer status,
            @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        log.info("分页获取所有护理等级:{}, {}, {}, {}", name, status, pageNum, pageSize);
        PageResponse<NursingLevelVo> pageResponse = nursingLevelService.getAll(name, status, pageNum, pageSize);
        return BaseResponse.success(pageResponse);
    }

    /**
     * 获取所有护理等级
     */
    @GetMapping("/listAll")
    public BaseResponse<List<NursingLevelVo>> listAll() {
        log.info("获取所有护理等级");
        return BaseResponse.success(nursingLevelService.listAll());
    }


    /**
     * 获取护理等级详情
     */
    @GetMapping("/{id}")
    public BaseResponse<NursingLevelVo> getInfo(@PathVariable Integer id) {
        log.info("获取护理等级详情:{}", id);
        return BaseResponse.success(nursingLevelService.getInfo(id));
    }


    /**
     * 新增护理等级
     */
    @PostMapping("/insert")
    public BaseResponse<Boolean> add(@RequestBody NursingLevelDto nursingLevelDto) {
        log.info("新增护理等级:{}", nursingLevelDto);
        return nursingLevelService.add(nursingLevelDto) ? BaseResponse.success(true) :
                BaseResponse.error(false);
    }


    /**
     * 编辑护理等级
     */
    @PutMapping("/update")
    public BaseResponse<Boolean> edit(@RequestBody NursingLevelDto nursingLevelDto) {
        log.info("编辑护理等级:{}", nursingLevelDto);
        return nursingLevelService.edit(nursingLevelDto) ? BaseResponse.success(true) :
                BaseResponse.error(false);
    }

    /**
     * 删除护理等级
     */
    @DeleteMapping("/delete/{id}")
    public BaseResponse<Boolean> remove(@PathVariable Integer id) {
        log.info("删除护理等级:{}", id);
        return nursingLevelService.deleteNursingLevelById(id) ? BaseResponse.success(true) :
                BaseResponse.error(false);
    }

    /**
     * 启用或禁用护理等级
     */
    @PutMapping("/{id}/status/{status}")
    public BaseResponse<Boolean> enableOrDisableNursingLevel(@PathVariable("id") Integer id,
                                                               @PathVariable("status") Integer status) {
        log.info("启用或禁用护理等级:{}, {}", id, status);
        return nursingLevelService.enableOrDisableNursingLevel(id, status) ? BaseResponse.success(true) :
                BaseResponse.error(false);
    }

}
